﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public class GameEndPage : EventManager {

    public Text time;
    public Text roomID;
    public Text chapterCounts;
    public GameObject playerGroup;
    public Button WXShareBtn;
    public Button goToGameHallBtn;


    void Start()
    {
        AddListenerToButton(WXShareBtn, WXShareClick);
        AddListenerToButton(goToGameHallBtn, GoToGameHallClick);
    }

    public override void InformationSetting()
    {
        SetText(time, "结束时间：" + System.DateTime.Now.ToString());
        SetText(roomID, "房间号 : " + GameRoomModel.GetInstance().RoomID);
        SetText(chapterCounts, string.Format("局数： ({0}/{1})", GameRoomModel.GetInstance().CurrentChapter, GameRoomModel.GetInstance().MaxChapter));
        LoadGameEndItem();
    }

    private void LoadGameEndItem()
    {
        foreach (var item in GameRoomModel.GetInstance().playerDic.Values)
        {
            var temp = TooL.LoadPrefab(playerGroup, "GameEndItem");
            temp.GetComponent<GameEndItemPage>().InitGameEndItem(item);
        }
    }

    //分享战绩截图
    private  void WXShareClick()
    {
        LoginAndShare.Controller.sharePng();
    }

    //返回大厅
    private  void GoToGameHallClick()
    {
        if (GameObject.Find("GameRoomPage(Clone)"))
        {
            GameController.GetInstance().DeleteAllExceptGameHall();
        }
        else
        {
            Debug.Log("没有找到战斗预设体");
        }
    }
}
         